<template>
  <CardVue height="1.6rem" title="年度检查" style="margin-bottom: 0.3rem">
    <div class="grid">
      <div
        class="grid-item"
        @click="open({ title: '应参检', query: { examineYear } }, NJJLWNJAll)"
      >
        <div class="grid-item-title">应参检</div>
        <div class="grid-item-num">{{ annualCheckData['应参检'] || 0 }}</div>
      </div>
      <div
        class="grid-item"
        @click="
          openAlreadyTested(
            { title: '已参检', query: { examineYear } },
            NJJLLBZTHttp
          )
        "
      >
        <div class="grid-item-title">已参检</div>
        <div class="grid-item-num">{{ annualCheckData['已参检'] || 0 }}</div>
      </div>
      <div
        class="grid-item"
        @click="open({ title: '未参检', query: { examineYear } }, NJJLWNJHttp)"
      >
        <div class="grid-item-title">未参检</div>
        <div class="grid-item-num">{{ annualCheckData['未参检'] || 0 }}</div>
      </div>
      <div
        class="grid-item"
        @click="
          openAlreadyTested(
            { title: '年检合格', query: { examineYear, approveStatus: 1 } },
            NJJLLBZTHttp
          )
        "
      >
        <div class="grid-item-title">年检合格</div>
        <div class="grid-item-num">{{ annualCheckData['合格'] || 0 }}</div>
      </div>
      <div
        class="grid-item"
        @click="
          openAlreadyTested(
            { title: '基本合格', query: { examineYear, approveStatus: 2 } },
            NJJLLBZTHttp
          )
        "
      >
        <div class="grid-item-title">基本合格</div>
        <div class="grid-item-num">{{ annualCheckData['基本合格'] || 0 }}</div>
      </div>
      <div
        class="grid-item"
        @click="
          openAlreadyTested(
            { title: '不合格', query: { examineYear, approveStatus: 3 } },
            NJJLLBZTHttp
          )
        "
      >
        <div class="grid-item-title">不合格</div>
        <div class="grid-item-num">{{ annualCheckData['不合格'] || 0 }}</div>
      </div>
    </div>
  </CardVue>
  <PopupVue ref="PopupVueRef" />
  <PopupAlreadyTested ref="PopupAlreadyTestedRef" />
</template>
<script setup lang="ts">
import CardVue from '@/views/largeScreen/components/card/card.vue'
import { onMounted, ref } from 'vue'
import {
  annualCheck,
  NJJLWNJ,
  NJJLWNJAll,
  NJJLLBZT
} from '@/api/spotCheck/spotCheck'
import PopupVue from './popup.vue'
import PopupAlreadyTested from './popup-alreadyTested.vue'

const annualCheckData = ref({})
onMounted(() => {
  //年度检查
  annualCheck().then((res) => {
    //publicizeData.value = res.data
    annualCheckData.value = res.data.data
  })
})

const NJJLWNJHttp = async (params) => {
  const res = await NJJLWNJ(params)
  return {
    data: {
      list: res.rows
    },
    total: res.total
  }
}

const NJJLLBZTHttp = async (params) => {
  const res = await NJJLLBZT(params)
  return {
    data: {
      list: res.rows
    },
    total: res.total
  }
}

const year = new Date().getFullYear()

const examineYear = ref(year - 1)

const PopupVueRef = ref<InstanceType<typeof PopupVue> | null>(null)

const open = (query, http) => {
  console.log('点击了', query)
  PopupVueRef.value?.show(query, http)
}

const PopupAlreadyTestedRef = ref<InstanceType<
  typeof PopupAlreadyTested
> | null>(null)

const openAlreadyTested = (query, http) => {
  PopupAlreadyTestedRef.value?.show(query, http)
}
</script>
<style scoped lang="scss">
.grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  grid-gap: 0.05rem;
  grid-row-gap: 0.1rem;
  box-sizing: border-box;
  padding: 0.1rem;
  .grid-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    height: 100%;
    .grid-item-title {
      color: #00ffd3;
      font-size: 0.16rem;
      font-weight: 300;
    }
    .grid-item-num {
      color: #fff;
      font-size: 0.29rem;
      font-weight: 500;
    }
  }
}
</style>
